<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
	/**
	 * 订单来源
	 *
	 */
class From extends MY_Controller{
		
	function __construct(){
		parent::__construct();
		$this->load->model('order/FromModel', '' , true);
	}
	
	/*
	 * 订单来源管理
	 */
	function index($index=1,$size=10){
		$view_data = $this->_data($index,$size);
		$this->load->view('order/from/index',$view_data);
	}
	
	/*
	 * ajax 返回订单来源列表
	 */
	function data_list($index=1,$size=10){
		$view_data = $this->_data($index,$size);
		$this->load->view('order/from/data_list',$view_data);
	}
	
	function _data($index=1,$size=20) {
		$result = $this->FromModel->select($index,$size);
		$data['list'] = $result['data'];
		$this->load->library('Pagination');
		$data['pages'] = $this->pagination->get_pages(base_url().index_page().'/order/from/index',$result['total'],$size,$index);
		return $data;
	}
	/*
	 * exist 检测订单来源名称是否存在
	 */
	function exist($name) {
		$name = urldecode($name);
		$data['state'] = $this->FromModel->isExistName($name);
		$this->_output_json($data);
	}
	/*
	 * add 新增订单来源
	 * 
	 * $redirect=''
	 */
	function add() {
		$data['state'] = $this->FromModel->insert($_POST);
		$data['message'] = $data['state'] > 0 ? '新增订单来源成功。':'新增订单来源失败！';
		$this->_output_json($data);
	}
	
	function show_edit($id) {
		$view_data['o'] = $this->FromModel->selectById($id);
		$view_data['action'] = 'edit';
		$view_data['view'] = 'order/from/add_edit';
		$this->load->view('view',$view_data);
	}
	
	function edit() {
		$data['state'] = $this->FromModel->update($_POST);
		$data['message'] = $data['state'] > 0 ? '编辑订单来源订单来源':'编辑订单来源失败！';
		$this->_output_json($data);
	}
	function delete($id) {
		$data['state'] = $this->FromModel->delete($id);
		$data['message'] = $data['state'] ? '删除订单来源成功。':'删除订单来源失败！';	
		$this->_output_json($data);
	}

}
?>